package io;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;

public class ByteStreamAppendWriteFile {
	
	public final static String filename = CreateFolder.foldername + File.separator + "stream.txt";
	
	/**
	 * 追加新的字节流写入文件，不覆盖原有的
	 * @param args
	 * 
	 */
	public static void main(String[] args) {
		File file = new File(filename);
		try {
			OutputStream out = new FileOutputStream(file,true);
			//
			String str="早安";
			byte[] b=str.getBytes();
			System.out.println("调用write(bytes[])方法，写入字节流");
			System.out.println("字节流长度："+b.length);
	        out.write(b);
	        
	        String str2 = "十八大";
	        byte[] a = str2.getBytes();
			System.out.println("\n调用write(int)方法，写入单个字节");
	        for (int i = 0; i < a.length; i++) {
				System.out.println("将要写入的字节是："+a[i]);
				out.write(a[i]);
			}
	        out.close();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}

}
